package com.wpw.java7demo.collections;

import java.util.HashMap;
import java.util.Map;

class MapKey {
	private String name;
	
	private Integer sex;
	
	public MapKey() {
	}
	
	public MapKey(String name, Integer sex) {
		super();
		this.name = name;
		this.sex = sex;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getSex() {
		return sex;
	}

	public void setSex(Integer sex) {
		this.sex = sex;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((sex == null) ? 0 : sex.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		MapKey other = (MapKey) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (sex == null) {
			if (other.sex != null)
				return false;
		} else if (!sex.equals(other.sex))
			return false;
		return true;
	}
	
	
	
}

public class MapDemo {
	
	public static void main(String[] args) {
		Map<MapKey, String> map = new HashMap<>();
		MapKey a = new MapKey("wpw",1);
		MapKey b = new MapKey("wpw",1);
		
		map.put(a, "1");
		map.put(b, "2");
		System.out.println(map);;
		
	}

}
